package com.shuaqiu.sboot.common.dict;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;

@JsonComponent
public class DictEnumVoSerializer extends JsonSerializer<DictEnumVo> {

    @Override
    public void serialize(final DictEnumVo value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException {
        if (value == null || value.dictEnum == null) {
            gen.writeNull();
            return;
        }

        gen.writeStartObject();
        gen.writeFieldName("key");
        gen.writeString(value.getKey());
        gen.writeFieldName("desc");
        gen.writeString(value.getDesc());
        gen.writeEndObject();
    }
}
